/**
 * Copyright (C), 2021, 因特驰
 * FileName: DemoServiceImpl
 * Author:   李晋武
 * Date:     2021/7/12 8:21
 * Description:
 * History:
 * 李晋武          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.esc.service;

import com.esc.mapper.DemoMapper;
import com.esc.model.Demo;
import com.esc.server.DemoServiceApi;
import com.esc.util.PageResult;
import com.esc.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author Yun
 * @create 2021/7/12
 * @since 1.0.0
 */
@RestController
public class DemoServiceImpl implements DemoServiceApi {

    @Autowired
    private DemoMapper demoMapper;

    @Override
    //@PostMapping("queryDemoList")
    public PageResult queryDemoList(PageUtil<Demo> pageUtil) {
        PageResult page = new PageResult();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("demo",pageUtil.getT());
        map.put("start",pageUtil.getStartIndex());
        map.put("size",pageUtil.getRows());
        int total = demoMapper.queryCount(map);
        List<Demo> list = demoMapper.queryDemoList(map);
        page.setTotal(total);
        page.setRows(list);
        return page;
    }

    @Override
    public void addDemo(Demo demo) {
        demoMapper.addDemo(demo);
    }

    @Override
    //@PostMapping("queryDemoById")
    public Demo queryDemoById(@RequestParam("demoid") Integer demoid) {
        return demoMapper.queryDemoById(demoid);
    }

    @Override
    public void updateDemo(Demo demo) {
        demoMapper.updateDemo(demo);
    }

    @Override
    public void deleteDemo(@RequestParam("demoid") Integer demoid) {
        demoMapper.deleteDemo(demoid);
    }
}